package com.example.blog2023.controller;

import com.example.blog2023.bean.dto.BlogsInputDto;
import com.example.blog2023.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;

import java.util.ArrayList;

/**
 * @author cfy
 * @date 2023/12/13
 **/
@Controller
@RequestMapping("/admin")
public class BlogsInputController {
    @Autowired
    private AdminService adminService;
    @PostMapping("/insert")
    public RedirectView insertBlog(@RequestParam(value = "format" ,required = false) String format,
                                   @RequestParam("title") String title,
                                   @RequestParam(value = "content" ,required = false) String content,
                                   @RequestParam(value = "type",required = false) String type,
                                   @RequestParam(value = "tag",required = false)ArrayList<String> labels,
//                                   @RequestParam(value = "indexPicture",required = false) String indexPicture,
                                   @RequestParam(value = "recommend",required = false) String recommend,
                                   @RequestParam(value = "shareInfo",required = false) String shareInfo,
                                   @RequestParam(value = "appreciation",required = false) String appreciation,
                                   @RequestParam(value = "comment",required = false) String comment
                                   ){
        BlogsInputDto blogsInputDto = BlogsInputDto.builder()
                .format(format)
                .title(title)
                .content(content)
                .type(type)
                .label(labels)
                .recommend(recommend)
                .shareInfo(shareInfo)
                .appreciation(appreciation)
                .comment(comment)
                .build();
        boolean b = adminService.insertBolg(blogsInputDto);
        RedirectView redirectView = new RedirectView();
        redirectView.setUrl("/admin/blogs");
        return  redirectView;
    }

}

